#ifndef SIMPLE_IO_HANDLE_COMMON_HPP
#define SIMPLE_IO_HANDLE_COMMON_HPP

#include "handle_common.h"

namespace simple::io
{

	template <typename Config>
	void custom_deleter<Config>::operator()(pointer p) const noexcept
	{
		Config::deleter(static_cast<handle>(p));
	}

	template <typename Config>
	custom_deleter<Config>::pointer::pointer() noexcept
		: h(Config::null())
	{}

	template <typename Config>
	custom_deleter<Config>::pointer::pointer(handle h) noexcept
		: h(h)
	{}

	template <typename Config>
	custom_deleter<Config>::pointer::pointer(std::nullptr_t) noexcept
		: pointer()
	{}

	template <typename Config>
	[[nodiscard]]
	bool custom_deleter<Config>::pointer::operator==(pointer other) const noexcept
	{ return h == other.h; }
	template <typename Config>
	[[nodiscard]]
	bool custom_deleter<Config>::pointer::operator!=(pointer other) const noexcept
	{ return !(*this == other); }

	template <typename Config>
	[[nodiscard]]
	custom_deleter<Config>::pointer::operator handle() const noexcept
	{ return h; }

	template <typename Config>
	[[nodiscard]]
	custom_deleter<Config>::pointer::operator bool() const noexcept
	{ return *this != pointer(); }

} // namespace simple::io

#endif /* end of include guard */
